//index.js
const app=getApp();
Page({
  data: {
    iconUrls:[
      {
        name:"狼人",
        src:"../../images/wolf.jpg",
        count:0,
      },
      {
        name:"平民",
        src:"../../images/human.jpg",
        count:0,
      },
      {
        name:"守卫",
        src:"../../images/guard.jpg",
        count:0,
      },
      {
        name:"女巫",
        src:"../../images/witch.jpg",
        count:0,
      },
      {
        name:"预言家",
        src:"../../images/prophet.jpg",
        count:0,
      },
      {
        name:"猎人",
        src:"../../images/hunter.jpg",
        count:0,
      },
      {
        name:"白痴",
        src:"../../images/fool.jpg",
        count:0,
    },  


],
    animation:[{
      front:null,
      reverse:null
    },
    {
      front:null,
      reverse:null
    }],
  },
  onLoad: function(options) {
    if(app.globalData.iconUrls.length){
      this.setData({
        iconUrls:app.globalData.iconUrls,
      })
    }

    this.animate=wx.createAnimation({
      duration: 446,
      timingFunction: 'linear'
     })

  },
  onShow:function(){
    app.globalData.count=[];// 所有人玩家信息
    app.globalData.day=0;// 当前天数，以此来决定上帝可执行的操作
    app.globalData.isMed=[false,false];// 判断女巫是否用药
    app.globalData.isHunter=false;// 判断是否有猎人牌，防止第二夜继续问询猎人玩家
    app.globalData.isFool=false;// 判断是否有白痴牌，防止第二夜继续问询白痴玩家
    app.globalData.guardOne=null; // 记录守卫前一晚守护的人
  },
  // 点击按钮开始游戏
  clickBegin(e){
    app.globalData.iconUrls=this.data.iconUrls;
    wx.setStorageSync('iconUrls',this.data.iconUrls);
    wx.reLaunch({
      url: '../mainGame/index',
    })
  },
  // 输入个数
  inputCount(e){
    const {value}=e.detail;
    const {index}=e.currentTarget.dataset;
    this.data.iconUrls[index].count=+value;
  },
  // 点击旋转
  rotateFn(e){
    const {id,index}=e.currentTarget.dataset;
    if(id==1){
      this.data.animation[index].front = this.animate.rotateY(180).step().export();
      this.data.animation[index].reverse = this.animate.rotateY(0).step().export();
    }
    else{
      this.data.animation[index].front = this.animate.rotateY(0).step().export();
      this.data.animation[index].reverse = this.animate.rotateY(180).step().export();
    }
    const tempAni=this.data.animation;
    const tempIcon=this.data.iconUrls;
    this.setData({
      animation:tempAni,
      iconUrls:tempIcon,
    })
  },
  // 点击人物确定使用的人物
  clickRole(e){
    const index=e.currentTarget.dataset.index;
    // 判断选中了哪位神职
      this.data.iconUrls[index].count=!this.data.iconUrls[index].count;
      const temp=this.data.iconUrls;
      this.setData({
        iconUrls:temp,
      })
  },
onReady(){
 
},
})
